package ru.incoremedia.gwttest.application.client.action;

import com.google.gwt.rpcforms.client.handler.AsyncResultHandler;
import ru.incoremedia.gwttest.application.client.context.ClientContext;
import ru.incoremedia.gwttest.application.client.dto.AuthInfo;
import ru.incoremedia.gwttest.core.client.action.AsyncAction;
import ru.incoremedia.gwttest.core.client.form.MyRefreshForm;


public class GetAuthInfoAction implements AsyncAction<AuthInfo> {

    public final static String AUTH_INFO_CONTROLLER = "authInfoController";

    @Override
    public void execute(final AsyncResultHandler<AuthInfo> handler) {
        MyRefreshForm form = new MyRefreshForm(AUTH_INFO_CONTROLLER);

        form.refresh(new AsyncResultHandler<AuthInfo>() {
            @Override
            public void onSuccess(AuthInfo authInfo) {
                ClientContext.getInstance().setAuthInfo(authInfo);
                handler.onSuccess(authInfo);
            }
        });
    }
}
